<script>
   export var username = '';
    let password = '';
    let response='';
    let checkone=true;

    import { sharedParam,shareName} from '../stores/userStore' 

 let login=(e)=>{
   fetch('/api/login',{
    method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({ username, password }),
  })
  .then((response) => response.text())
 .then((data)=>{
  console.log(data);
 if(data == "admin"){
      sharedParam.set(true)
      shareName.set(username)
      location.href = '/admin';
 }
 if(data == "student"){
  console.log("666");
 sharedParam.set(true)
 shareName.set(username)
 localStorage.setItem("username",username);
 location.href = '/admin/student';
 }
 
 })
  .catch((err)=>{
    response = err ;
  });
  
}



  </script>
  
  <style>

  
    .welcome-text {
      /* font-family: 'Comic Sans MS', cursive;
      font-size: 30px;
      color: red;
      margin-bottom: 20px; */
           font-weight: bold; /* 设置字体为粗体 */
  font-size: 24px; /* 设置字体大小 */
  color: #ff0000; /* 设置字体颜色为红色 */
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5); /* 设置文本阴影 */
  align-items: center;
    }
  
    .login-form {
      display: flex;
      flex-direction: column;
      align-items: center;
      width: 300px;
      margin: 0 auto;
    }
  
    .login-form input {
      margin-bottom: 10px;
      padding: 5px;
      width: 100%;
      border: 1px solid #ccc;
      border-radius: 4px;
      color: black;
    }
  
    .login-form button {
      padding: 10px 20px;
      background-color: #2c27b0;
      color: white;
      border: none;
      border-radius: 4px;
      cursor: pointer;
    }
  
    .login-form button:hover {
      background-color: #45a049;
    }
  </style>
   <div class="login-form">
    <h1 class="welcome-text">欢迎来到选课管理系统</h1>
        <form >
            <input type="text" placeholder="用户名" bind:value={username} required />
            <input type="text" placeholder="密码" bind:value={password} required />
            <button on:click={login}>登录</button>
        </form>
    </div>